package com.wlient.basic.skill;

import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author: 史炜立
 * @description: TODO
 * @date: 2021/10/15 10:34
 */
@Component
public class selectDate {

    private static void select() {
        String[] strA = "1,2,3,4,5,5,6,7,8,9,10".split(",");
        String[] strB = "2,3,5,5,1000".split(",");

        List<String> ListA = new ArrayList<>(Arrays.stream(strA).distinct().collect(Collectors.toList()));

        List<String> ListB = new ArrayList<>(Arrays.asList(strB));
        //交集
        ListA.retainAll(ListB);
        System.out.println(ListA);

        //差集
        List<String> ListC = new ArrayList<>(Arrays.stream(strA).distinct().collect(Collectors.toList()));
        ListC.removeAll(ListB);
        System.out.println(ListC);

        //并集
        List<String> ListD = new ArrayList<>(Arrays.stream(strA).distinct().collect(Collectors.toList()));
        ListD.removeAll(ListB);
        ListD.addAll(ListB);
        System.out.println(ListD);

        //并集，set实现
        Set<String> setA = new HashSet<>(Arrays.stream(strA).collect(Collectors.toSet()));
        Set<String> setB = new HashSet<>(Arrays.stream(strB).collect(Collectors.toSet()));
        Set<String> setC = new HashSet<>();
        setC.addAll(setA);
        setC.addAll(setB);
        System.out.println(setC);

        //stream实现
        List<String> StreamA = new ArrayList<>(Arrays.asList(strA));
        List<String> StreamB = new ArrayList<>(Arrays.asList(strB));
        StreamA.stream().distinct().filter(i->StreamB.contains(i)).forEach(System.out::print);

        List<String> StreamD = new ArrayList<>(Arrays.asList(strA));
        StreamD.contains("AA");
        StreamD.stream().forEach(System.out::print);
    }
    public static void main(String[] args) {
        select();
    }
}
